<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户ID">
              <a-input placeholder="请输入用户ID" v-model="queryParam.userId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务ID">
              <a-input placeholder="请输入任务ID" v-model="queryParam.taskId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">查看</a>
        </span>
        <!-- 任务状态 -->
        <template slot="taskStatusSlot" slot-scope="taskStatus">
          <a-tag v-if="taskStatus=='commit'" color="lightsteelblue">创建任务</a-tag>
          <a-tag v-if="taskStatus=='running'" color="darkseagreen">进行中</a-tag>
          <a-tag v-if="taskStatus=='failed'" color="orangered">处理失败</a-tag>
          <a-tag v-if="taskStatus=='success'" color="limegreen">处理成功</a-tag>
        </template>
        <!-- 接口类型 -->
        <template slot="apiTypeSlot" slot-scope="apiType">
          <a-tag v-if="apiType==72056" color="lightseagreen">人脸驱动</a-tag>
          <a-tag v-if="apiType==72057" color="lightsalmon">虚拟主播</a-tag>
        </template>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <faceDynamicTask-modal ref="modalForm" @ok="modalFormOk"></faceDynamicTask-modal>
  </a-card>
</template>

<script>
  import FaceDynamicTaskModal from './modules/FaceDynamicTaskModal'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'

  export default {
    name: "FaceDynamicTaskList",
    mixins: [JeecgListMixin],
    components: {
      FaceDynamicTaskModal
    },
    data() {
      return {
        description: '人脸动态任务管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '用户ID',
            align: "center",
            dataIndex: 'userId'
          },
          {
            title: '任务ID',
            align: "center",
            dataIndex: 'taskId'
          },
          {
            title: '任务状态',
            align: "center",
            dataIndex: 'taskStatus',
            scopedSlots: {customRender: 'taskStatusSlot'}
          },
          {
            title: '接口类型',
            align: "center",
            dataIndex: 'apiType',
            scopedSlots: { customRender: 'apiTypeSlot'}
          },
          {
            title: '创建时间                                                                                                                                                                                                                                 ',
            align: "center",
            dataIndex: 'createTime'
          },
          {
            title: '完成时间                                                                                                                                                                                                                                 ',
            align: "center",
            dataIndex: 'finishDate'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'},
          }
        ],
        url: {
          list: "/facedynamic/faceDynamicTask/list",
          delete: "/facedynamic/faceDynamicTask/delete",
          deleteBatch: "/facedynamic/faceDynamicTask/deleteBatch",
          exportXlsUrl: "facedynamic/faceDynamicTask/exportXls",
          importExcelUrl: "facedynamic/faceDynamicTask/importExcel",
        },
      }
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {}
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>